package com.jr.service.impl;

import com.jr.mapper.PetMapper;
import com.jr.pojo.Pet;
import com.jr.service.PetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Service
public class PetServiceImpl implements PetService {

    @Autowired
    private PetMapper petMapper;

    @Override
    public boolean addPet(Pet pet) {
        return petMapper.insertPet(pet) > 0;
    }

    @Override
    public ArrayList<Pet> getPetsByOwnerId(Integer ownerId) {
        return petMapper.selectByOwnerId(ownerId);
    }

    @Override
    public Pet getPetById(Integer petId) {
        return petMapper.selectById(petId);
    }

    @Override
    public boolean updatePet(Pet pet) {
        return petMapper.updatePet(pet) > 0;
    }

    @Override
    public boolean deletePet(Integer petId) {
        return petMapper.deletePet(petId) > 0;
    }

    @Override
    public ArrayList<Pet> getPetsByPage(Integer ownerId, Integer pageIndex, Integer pageSize) {
        int offset = (pageIndex - 1) * pageSize;
        return petMapper.selectByPage(ownerId, offset, pageSize);
    }

    @Override
    public int getPetCountByOwnerId(Integer ownerId) {
        return petMapper.countByOwnerId(ownerId);
    }
}
